<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<body>
<div>
    <h3>登录</h3>
    用户名：<input type="text" id="username"><br>
    密 码：<input type="password" id="password"><br>
    <button>登录</button>

    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script>
        let button=document.querySelector("button");
        button.onclick=function(){
            let inputs = document.querySelectorAll('input');
            let username = inputs[0].value;
            let password = inputs[1].value;
            if (username == '' || password == '') {
                alert('当前输入框内容为空!');
                return;
            }
            let data={
                username:username,
                password:password
            }
            $.ajax({
                type:'post',
                url:'/login',
                data:data,
                success:function (body) {
                    if(body.status==0){
                        alert("登录成功！");
                        console.log("登录成功");
                        location.assign("/index.html");
                    }else{
                        alert("登陆失败，用户名或密码为空！");
                        username="";
                        password="";
                    }

                },
            });
        }


    </script>
</div>
</body>
</html>